package com.zkld.frame.service.impl;

import com.zkld.frame.dto.ResponseDTO;
import com.zkld.frame.entitys.User;
import com.zkld.frame.mapper.UserMapper;
import com.zkld.frame.service.UserService;
import com.zkld.frame.util.ResponseFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public ResponseDTO registered(User user) {
        userMapper.insert(user);
        return ResponseFactory.getResponse(null,"success");
    }

    @Override
    public boolean login(Integer userId, String password) {
        User user = userMapper.selectByPrimaryKey(userId);
        if (user != null && user.getPassword().equals(password)){
            return true;
        }
        return false;
    }
}
